package cn.uce.cc.ops.job;

import cn.uce.base.vo.CcRpCallAllDateVo;
import cn.uce.elastic.job.base.UceDataflowJob;
import cn.uce.elastic.job.base.UceSimpleJob;
import cn.uce.ics.base.entity.cs.RpCallalldata;
import cn.uce.job.api.service.biz.IRpCallalldataBiz;
import com.alibaba.fastjson.JSON;
import com.dangdang.ddframe.job.api.ShardingContext;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;


 /**
  * 满意度发送短信
  *查询前一天的满意度数据进行调用接口拼接短信内容
   * @Author liupan
   * @Description
   * @Date  2020-06-15 10:48
   */
public class SatisfiedMessageJob extends UceSimpleJob {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Resource
    private IRpCallalldataBiz rpCallalldataBiz;


     @Override
     public void doExecute(ShardingContext shardingContext) {
         long csPrepayTxDealJob = System.currentTimeMillis();
         logger.info("SatisfiedMessageJob分片总数：" + shardingContext.getShardingTotalCount() + " fetchData分片项: "
                 + shardingContext.getShardingItem() + "线程ID: " + Thread.currentThread().getId());

         /**
          * 满意度短信开关,
          */
         if(!rpCallalldataBiz.getSatisFiedMessageSwtich()){
             return ;
         }

         CcRpCallAllDateVo vo = new CcRpCallAllDateVo();
         vo.setShardingItem(String.valueOf(shardingContext.getShardingItem()));
         vo.setShardingTotalCount(String.valueOf(shardingContext.getShardingTotalCount()));
         DateTime dateTime = new DateTime(new Date());
         Date beginTimeday = dateTime.minusDays(1).withMillisOfDay(0).toDate();
         Date endTimeday = dateTime.minusDays(0).withMillisOfDay(0).toDate();
         vo.setBeginTime(beginTimeday);
         vo.setEndTime(endTimeday);
         // 只查询出删除标识为0的数据进行处理
         List<RpCallalldata>  resultList=rpCallalldataBiz.findNeedSendMessageList(vo);
         long csPrepayTxDealJobend = System.currentTimeMillis();
         logger.warn("CsPrepayTxDealJob:finduse:" + (csPrepayTxDealJobend - csPrepayTxDealJob) + "ms"+"size:"+resultList.size()+
                 "resultList"+ JSON.toJSONString(resultList));
         if (resultList != null && !resultList.isEmpty() ){
             rpCallalldataBiz.pushMessage(resultList);
         }
     }
 }
